import React, { Component } from 'react';
import { Table, Spin } from 'antd';
import '../../styles/table.scss'
import { createTableModel, getTableModel } from '../tableModel/tableBaseModel';
import { pxToRem, pxToPx,pxToVh } from '../../utils/adaptive.js';
class screenTable extends Component {
    constructor(props) {
        super(props);
        this.state = {
            model: {
                dataSource: [],
                columns: [],
            },
        }
    }
    componentDidMount() {
        const { area } = this.props;
        createTableModel('/getDashBoardData?configName=dashBoardNo2Config', area, (model) => {
            this.setState({
                model,
            })
        });

    }
    componentWillReceiveProps(nextProps) {
        const { area } = nextProps;
        createTableModel(null, area, (model) => {
            this.setState({
                model,
            })
        });
    }
    render() {
        let template = <span></span>;
        if (this.state.model.dataSource.length && this.state.model.columns.length) {
            this.state.model.dataSource.map((item, index) => {
                item.sales_map_03 = Math.round(item.sales_map_03);
                item.sales_map_04 = Math.round(item.sales_map_04);
                item.sales_map_08 = Math.round(item.sales_map_08);
            })
            template = <Table
                dataSource={this.state.model.dataSource}
                columns={this.state.model.columns}
                bordered={true}
                pagination={false}
                rowClassName={(record, index) => {
                    if (index === 0) {
                        return 'table-total'
                    }
                }}
            />;
        }
        return (<div id="ScreenTable" style={{ width: pxToRem(490), position: 'absolute', zIndex: '999999', overflow: 'hidden', textAlign: 'center',display:'none'}}>
            {
                template
            }
        </div>);
    }
}
export default screenTable;